{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "toc": true
   },
   "source": [
    "<h1>Table of Contents<span class=\"tocSkip\"></span></h1>\n",
    "<div class=\"toc\"><ul class=\"toc-item\"></ul></div>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**变量的调用**\n",
    "- 将消息存储到变量之中并打印该变量\n",
    "- 改变变量的值并打印 `replace('原始参数','修改为')`为替换函数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "this is a simple message\n"
     ]
    }
   ],
   "source": [
    "message = 'this is a simple message'\n",
    "print(message)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "this is a simple message\n",
      "that is a simple message\n"
     ]
    }
   ],
   "source": [
    "message = 'this is a simple message'\n",
    "print(message)\n",
    "new_message = message.replace('this', 'that')\n",
    "print(new_message)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**字符串**\n",
    "- 内置函数修改字符串的大小写 \n",
    "    1. `title()`将首字母大写其他字母转小写，可以让Ada, ADA, aDA视为同一个名字\n",
    "    2. `upper()`将单词全部换成大写\n",
    "    3. `lower()`将单词全部换成小写\n",
    "- 拼接字符串\n",
    "    1. 字符串的拼接 '+'，还可以更改字母连接词为'-'\n",
    "    2. 第8行添加修饰的输出\n",
    "    3. 第9-10行存储到一个变量中，然后输出\n",
    "- 添加和删除空白\n",
    "    1. `\\t` 为添加换行符,向右移动8个字符的空白, `\\n` 为换行符\n",
    "    2. `strip()` 移除字符串首尾处的值，默认移除空格\n",
    "        1. `rstrip()` 移除右侧的空格字符\n",
    "        2. `lstrip()` 移除左侧的空格字符\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Ada Lovelace\n",
      "ADA LOVELACE\n",
      "ada lovelace\n"
     ]
    }
   ],
   "source": [
    "name = 'aDa loveLace'\n",
    "print(name.title())\n",
    "print(name.upper())\n",
    "print(name.lower())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "ada ti lovelace\n",
      "ada-ti-lovelace\n",
      "Hello, Ada Ti Lovelace!\n",
      "Hello, Ada Ti Lovelace!\n"
     ]
    }
   ],
   "source": [
    "first_name = 'ada'\n",
    "last_name = 'lovelace'\n",
    "middle_name = 'ti'\n",
    "full_name = first_name + ' ' + middle_name + ' ' + last_name\n",
    "full_name_1 = first_name + '-' + middle_name + '-' + last_name\n",
    "print(full_name)\n",
    "print(full_name_1)\n",
    "print(\"Hello, \" + full_name.title() + \"!\")\n",
    "message = \"Hello, \" + full_name.title() + \"!\"\n",
    "print(message)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Python\n",
      "\tPython\n",
      "Languages:\n",
      "Python\n",
      "C\n",
      "Java\n",
      "原始字符串:\n",
      " Python \n",
      "删除首尾空格:\n",
      "Python\n"
     ]
    }
   ],
   "source": [
    "print(\"Python\")\n",
    "print(\"\\tPython\")\n",
    "print(\"Languages:\\nPython\\nC\\nJava\")\n",
    "favorite_language = ' Python '\n",
    "print(\"原始字符串:\")\n",
    "print(favorite_language)\n",
    "print(\"删除首尾空格:\")\n",
    "print(favorite_language.strip())"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**字符串习题**\n",
    "1. 姓名存储到变量中并输出含有姓名的消息\n",
    "2. 姓名大写，小写，首字母大写展示\n",
    "3. 固定格式输出人物名字和名言\n",
    "4. 剔除人名的空白"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Hello Eric,would you like to learn some Python today?\n",
      "\n",
      "\n",
      "ASHH HASNJ\n",
      "ashh hasnj\n",
      "Ashh Hasnj\n",
      "\n",
      "\n",
      "Linus Torvalds once said, “Talk is cheap, show me the code”\n",
      "\n",
      "\n",
      "\tLinus Torvalds\t\n",
      "Linus Torvalds\t\n",
      "\tLinus Torvalds\n",
      "Linus Torvalds\n"
     ]
    }
   ],
   "source": [
    "#1\n",
    "name_1 = \"Eric\"\n",
    "message_1 = \"Hello\" + \" \" + name_1 + \",\" + \"would you like to learn some Python today?\"\n",
    "print(message_1)\n",
    "print(\"\\n\")\n",
    "#2\n",
    "name_2 = \"ashH HAsnj\"\n",
    "print(name_2.upper())\n",
    "print(name_2.lower())\n",
    "print(name_2.title())\n",
    "print(\"\\n\")\n",
    "#3\n",
    "name_3 = \"Linus Torvalds\"\n",
    "message_3 = \"Talk is cheap, show me the code\"\n",
    "print(name_3 + \" once said,\" + \" “\" + message_3 + \"”\")\n",
    "print(\"\\n\")\n",
    "#4\n",
    "name_4 = \"\\tLinus Torvalds\\t\"\n",
    "print(name_4)\n",
    "print(name_4.lstrip())\n",
    "print(name_4.rstrip())\n",
    "print(name_4.strip())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The Zen of Python, by Tim Peters\n",
      "\n",
      "Beautiful is better than ugly.\n",
      "Explicit is better than implicit.\n",
      "Simple is better than complex.\n",
      "Complex is better than complicated.\n",
      "Flat is better than nested.\n",
      "Sparse is better than dense.\n",
      "Readability counts.\n",
      "Special cases aren't special enough to break the rules.\n",
      "Although practicality beats purity.\n",
      "Errors should never pass silently.\n",
      "Unless explicitly silenced.\n",
      "In the face of ambiguity, refuse the temptation to guess.\n",
      "There should be one-- and preferably only one --obvious way to do it.\n",
      "Although that way may not be obvious at first unless you're Dutch.\n",
      "Now is better than never.\n",
      "Although never is often better than *right* now.\n",
      "If the implementation is hard to explain, it's a bad idea.\n",
      "If the implementation is easy to explain, it may be a good idea.\n",
      "Namespaces are one honking great idea -- let's do more of those!\n"
     ]
    }
   ],
   "source": [
    "import this"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.4"
  },
  "toc": {
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": true,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": true,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
